<!--
 * @Descripttion:
 * @version:
 * @Author: wangmu
 * @Date: 2022-05-25 11:07:49
 * @LastEditors: wangmu
 * @LastEditTime: 2022-06-02 16:25:07
-->
<template>
  <el-dialog title="修改" :close-on-click-modal="false" :visible.sync="visible" width="40%">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
      <el-form-item label="模板标题" prop="title">
        <el-input placeholder="请输入模板标题" v-model="dataForm.title"></el-input>
      </el-form-item>
      <el-form-item label="模板ID" prop="wx_tempid">
        <el-input placeholder="请输入模板" v-model="dataForm.wx_tempid"></el-input>
      </el-form-item>
      <el-form-item label="内容字段" prop="wx_field">
        <el-input placeholder="请输入内容字段" v-model="dataForm.wx_field"></el-input>
      </el-form-item>
      <el-form-item label="模板内容" prop="content">
        <el-input placeholder="请输入模板内容" v-model="dataForm.content"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  treeDataTranslate
} from '@/utils'
import seviceApi from '@/api/serviceApi.js'
export default {
  data () {
    return {
      visible: false,
      is_pass: 1,
      dataForm: {
        title: '',
        wx_tempid: '',
        wx_field: '',
        content: '',
        id: 0
      },
      dataRule: {
        title: [{
          required: true,
          message: '模板标题不能为空',
          trigger: 'blur'
        }],
        wx_tempid: [{
          required: true,
          message: '模板不能为空',
          trigger: 'blur'
        }],
        wx_field: [
          { required: true, message: '内容字段不能为空', trigger: 'blur' }
        ],
        content: [
          { required: true, message: '模板内容不能为空', trigger: 'blur' }
        ]
      }
    }
  },

  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
      })
    },
    info (data) {
      this.visible = true
      this.$nextTick(() => {
        this.dataForm.title = data.title
        this.dataForm.wx_tempid = data.wx_tempid
        this.dataForm.wx_field = data.wx_field
        this.dataForm.content = data.content
        this.dataForm.id = data.id
      })
    },
    // 修改
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) { //  saveNotifytemp(添加接口)
          seviceApi.updateNotice(this.dataForm).then(res => {
            if (res && res.data.code == 200) {
              this.$message({
                message: '修改成功',
                type: 'success'
              })
              this.visible = false
              this.$emit('updataList', 1)
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss">
</style>
